import React from "react"
import { /* HashRouter,  */BrowserRouter, Routes, Route, Navigate } from "react-router-dom"
import Login from "./pages/Login"
import NavPage from "./pages/nav/index"
const Home = React.lazy(() => import("./pages/Home"))
const AccountList = React.lazy(() => import("./pages/accountManage/AccountList"))
const AddAccount = React.lazy(() => import("./pages/accountManage/AddAccount"))
const AddShop = React.lazy(() => import("./pages/shopManage/AddShop"))
const ShopList = React.lazy(() => import("./pages/shopManage/ShopList"))
const UserCenter = React.lazy(() => import("./pages/nav/components/userCenter"))

export default function App() {
  const token = localStorage.token
  return (
    <React.Suspense fallback={<div>加载中...</div>}>
      <BrowserRouter>
        <Routes>
          <Route path="/" element={<Navigate to={token ? "/nav" : "/login"} />}></Route>
          <Route path="/login" element={<Login></Login>}></Route>
          <Route path="/nav" element={<NavPage></NavPage>}>
            <Route path="home" element={<Home></Home>}></Route>
            <Route path="accountList" element={<AccountList></AccountList>}></Route>
            <Route path="addAccount" element={<AddAccount></AddAccount>}></Route>
            <Route path="addShop" element={<AddShop></AddShop>}></Route>
            <Route path="shopList" element={<ShopList></ShopList>}></Route>
            <Route path="userCenter" element={<UserCenter></UserCenter>}></Route>
          </Route>
        </Routes>
      </BrowserRouter>
    </React.Suspense>
  )
}
